package kr.hkit.powerjava.chapter22.work;

import java.util.ArrayList;

public class DepartmentDAO implements DaoInterface<Department> {
	private ArrayList<Department> arList;
	
	public DepartmentDAO(ArrayList<Department> arList) {
		this.arList = arList;
	}

	@Override
	public void addItem(Department item) {
		arList.add(item);
	}

	@Override
	public Department serachItem(Department item) {
		if(arList.contains(item)) {
			return arList.get(arList.indexOf(item));
		} else {
			return null;
		}
	}

	@Override
	public void updateItem(Department item) {
		Department temp = arList.get(arList.indexOf(item));
		temp.setDeptNo(item.getDeptNo());
		temp.setDeptName(item.getDeptName());
		temp.setFloor(item.getFloor());

	}

	@Override
	public void delItem(Department item) {
		if(arList.contains(item)) {
			arList.remove(arList.indexOf(item));
		} else {
			System.out.println("해당 학생 정보 없음");
		}
	}

	@Override
	public void prnList() {
		prnHeader();
		for(Department item: arList) {
			System.out.println(item);
		}

	}

	@Override
	public void prnHeader() {
		String header = String.format("%s %s\t %s", "학과번호", "학과명", "위치");
		System.out.println(header);

	}

}
